package scuts.core;

import scuts.core.types.Option;
import utest.Assert;
using scuts.core.GetOrElse;

class GetOrElseTest 
{

  public function new() 
  {
    
  }
  
  public function testGetOrElseOption() 
  {
    var o = None;
    var u = 5;
    var val = o.getOrElse({u = 7; 2;});
    
    Assert.equals(7, u);
    Assert.equals(2, val);
    
  }
  
  public function testGetOrElseDynamic() 
  {
    var o:Int = null; // must be typed as Int, because of a compiler issue (http://code.google.com/p/haxe/issues/detail?id=594)
    
    var u = 5;
    var val = o.getOrElse({u = 7; 2;});
    
    Assert.equals(7, u);
    Assert.equals(2, val);
    
  }
  
  public function testGetOrElseOptionLazyness() 
  {
    var o = Some(3);
    var u = 5;
    var val = o.getOrElse({u = 7; 2;});
    
    Assert.equals(5, u);
    Assert.equals(3, val);
    
  }
  public function testGetOrElseDynamicLazyness() 
  {
    var o = 3;
    var u = 5;
    var val = o.getOrElse({u = 7; 2;});
    
    Assert.equals(5, u);
    Assert.equals(3, val);
    
  }
  
  public function testGetOrElseNoMacro() 
  {
    var o = Some(3);
    var u = 5;
    var val = o.getOrElse({u = 7; 2;});
    
    Assert.equals(5, u);
    Assert.equals(3, val);
    
  }
}